package com.yc.system.service.impl;


import com.yc.system.domain.Teacher;
import com.yc.system.dto.TeacherDto;
import com.yc.system.mapper.TeacherMapper;
import com.yc.system.service.IStudentService;
import com.yc.system.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service("TeacherServiceImpl")
public class TeacherServiceImpl implements ITeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private IStudentService studentService;

    @Override
    public List<TeacherDto> selectAll() {
        List<Teacher> teacherList = teacherMapper.selectAll();

        // 将教师信息转换为TeacherDto
        return teacherList.stream()
                .map(teacher -> {
                    // 查询教师所带学生人数
                    Integer stuNum = studentService.selectAllStudentsByTeacherId(teacher.getTeaId());

                    return new TeacherDto(
                            teacher.getTeaId(),
                            teacher.getTeaName(),
                            teacher.getSubject(),
                            stuNum.toString(), // 将查询到的学生人数传递给 TeacherDto
                            teacher.getTitleLevel(),
                            teacher.getDepartment(),
                            teacher.getEmploymentStatus()
                    );
                }).collect(Collectors.toList());
    }

    @Override
    public List<Map<String, String>> selectAllTeacherName() {
        return List.of();
    }

    @Override
    public String selectTeacherIdByName(String teaName) {
        return "";
    }


}
